package com.example.controller.ActiveMQ;

import com.example.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.jms.Queue;
import javax.jms.Topic;

import org.slf4j.LoggerFactory;
import org.slf4j.Logger;


@Controller
@RequestMapping("/testActiveMQ")
public class TestActiveMQController extends BaseController {

    private  static  Logger logger = LoggerFactory.getLogger(TestActiveMQController.class);


    //JMS 消息发送模版
    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private  Queue queue;

    @Autowired
    private  Topic topic;



    //private JmsConfig jmsConfig;

    // 发送Queue消息
    @RequestMapping(value = "/sendQueueMsg",method = {RequestMethod.GET})
    public void  sendQueueMsg(String name){
       System.out.println("发送：" + name);
       logger.info("name==={}",name);
       this.jmsMessagingTemplate.convertAndSend(this.queue,name);
    }

    // 发送Topic消息
    @RequestMapping(value = "/sendTopicMsg",method = {RequestMethod.GET})
    public void sendTopicMsg(String name) {
        System.out.println("发送：" + name);
        logger.info("name==={}",name);
        this.jmsMessagingTemplate.convertAndSend(this.topic, name);
    }
}
